Rails Test Prescriptions (for Jennifer Saldivar) by Noel Rappin

Rails Test Prescriptions (for Jennifer Saldivar) by Noel Rappin

Author:Noel Rappin
Language: eng
Format: epub, pdf
Tags: Pragmatic Bookshelf
ISBN: 1-934356-64-6
Publisher: The Pragmatic Bookshelf, LLC (271500)


context "with an admin user" do

setup do

login_as_admin

end

teardown do

logout

end

test "admin features"

# something administrative

end

end

context "with a regular user" do

setup do

login_as_normal

end

test "normal features"

# something normal

end

end

end

The tests in each context have the setup methods for that context run before each test. We can still use the standard Test::Unit setup and teardown blocks outside of any context. Those methods would be called first, before the context setup method, at the beginning of each test.

Since a simple Ruby method creates contexts, we can generate them dynamically in the same way that tests can be generated dynamically:

["admin", "root"].each do |role|

context "with a #{role} user" do

setup do

@user = User.new(:role => role)

end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.